import QtQuick 2.4
import QtQuick.Controls 2.2
import "buildview"

Item {
    width: 1000
    height: 700

    BroadcastPage {
        id: broadcastPage
        width: parent.width
        height: parent.height
        visible: true
    }

    MusicPage {
        id: musicPage
        width: parent.width
        height: parent.height
        visible: false
    }

    BuildView {
        id: spbuildview
        visible: false
        objectName: "objspbuildview"
        anchors.fill: parent
    }
    Connections {
        target: spbuildview
        onUsrBuildClicked: SPController.getFloorDevice(btype, bstrIndex)
    }
    Connections {
        target: SPController
        onSpEvent: {
            spbuildview.data[1].deviceEvent(isn, event, islt)
        }
        onSpInit: {
            spbuildview.data[1].createObject(type, sdisn, state, x, y, emgno)
        }
    }

    Connections {
        target: tabMusic
        onClicked: state = "statemusic"
    }

    DevRecordPage {
        id: devRecordPage
        x: 0
        y: 0
        visible: false
        opacity: 0
    }

    TabBar {
        id: tabBar
        x: 0
        y: 360
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        width: 400
        height: 40

        TabButton {
            id: tabBroadcast
            text: qsTr("Broadcast")
        }

        TabButton {
            id: tabMusic
            text: qsTr("Music")
        }

        TabButton {
            id: tabBuildView
            x: 0
            y: 0
            text: qsTr("BuildView")
        }

        TabButton {
            id: tabRecord
            text: qsTr("Record")
        }
    }

    Connections {
        target: tabBroadcast
        onClicked: state = "statebroadcast"
    }

    Connections {
        target: tabBuildView
        onClicked: state = "statebuildview"
    }

    Connections {
        target: tabRecord
        onClicked: state = "staterecord"
    }

    states: [
        State {
            name: "statemusic"

            PropertyChanges {
                target: broadcastPage
                visible: false
            }

            PropertyChanges {
                target: musicPage
                visible: true
            }

            PropertyChanges {
                target: devRecordPage
                visible: false
            }
        },
        State {
            name: "statebroadcast"

            PropertyChanges {
                target: devRecordPage
                visible: false
            }
        },
        State {
            name: "statebuildview"

            PropertyChanges {
                target: broadcastPage
                visible: false
            }

            PropertyChanges {
                target: spbuildview
                visible: true
            }

            PropertyChanges {
                target: devRecordPage
                visible: false
            }
        },
        State {
            name: "staterecord"

            PropertyChanges {
                target: broadcastPage
                visible: false
            }

            PropertyChanges {
                target: devRecordPage
                visible: true
                opacity: 1
            }
        }
    ]
}
